<?php

use yii\grid\GridView;
use common\helpers\Html;
use kartik\select2\Select2;
$this->title = '用户管理';
$this->params['breadcrumbs'][] = ['label' => $this->title];

?>

<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">
                    <?= $this->title; ?>
                    <small></small>
                </h3>
                <div class="box-tools">
                    <?= Html::create(['ajax-edit'], '创建', [
                        'data-toggle' => 'modal',
                        'data-target' => '#ajaxModal',
                    ]) ?>
                </div>
            </div>
            <div class="box-body table-responsive">
                <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    'filterModel' => $searchModel,
                    // 重新定义分页样式
                    'tableOptions' => ['class' => 'table table-hover'],
                    'columns' => [
                        [
                            'class' => 'yii\grid\SerialColumn',
                        ],
                        'ordernumber',
                        'cates.title',//商品名称
                        'cate.member_name',//用户id
                        'catss.address',
                        'catss.name',
                        [
                            'attribute'=>'省',
                            'value'=>'catss.titles',
                        ],
                        [
                            'attribute'=>'市',
                            'value'=>'catss1.title1',
                        ],
                        [
                            'attribute'=>'区',
                            'value'=>'catss2.title2',
                        ],
                        //'cets.',//用户收货地址
                        'integral',//商品需要积分
                        [
                            'attribute'=>'type',
                            'value'=>function($model){
                                    if ($model->type == 0){
                                        return '代发货';
                                    }elseif ($model->type == 1){
                                        return '已发货';
                                    }else{
                                        return '未知错误';
                                    }
                                },
                            'filter'=>Select2::widget(['name' =>'SearchModel[type]',
                                'data' => $menuDropDownList,
                                'value' =>$searchModel->type,


                                'options' => ['placeholder' => '请选择']
                            ]),
                            'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => '全部'],
                        ],
//                        [
//                            'attribute' => 'type',
//                            'filter'=>Select2::widget(['name' =>'SearchModel[type]',
//                                'data' => $menuDropDownList,
//                                'value' =>$searchModel->type,
//
//
//                                'options' => ['placeholder' => '请选择']
//                            ]),
//                            'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => '全部'],
//                        ],
                        [
                            'header' => "操作",
                            'class' => 'yii\grid\ActionColumn',
                            'template' => '{ajax-edit} {status} {destroy}',
                            'buttons' => [
                                'ajax-edit' => function ($url, $model, $key) {
                                    if($model->type==0){
                                        return Html::edit(['up', 'id' => $model->id], '发货', [
                                            'data-toggle' => 'modal',
                                            'data-target' => '#ajaxModal',
                                        ]);
                                    }
                                    return Html::edit(['up', 'type' => $model->id], '已发货', [
                                        'data-toggle' => 'modal',
                                        'data-target' => '#ajaxModal',
                                    ]);
                                },
                                'status' => function ($url, $model, $key) {
                                    return Html::status($model->status);
                                },
                                'destroy' => function ($url, $model, $key) {
                                    return Html::delete(['destroy', 'id' => $model->id]);
                                },
                            ],
                        ],
                    ],
                ]); ?>
            </div>
        </div>
    </div>